package com.zzj.portalwebsite.Controller;

import com.alibaba.fastjson.JSON;
import com.zzj.portalwebsite.entity.FeedBack;
import com.zzj.portalwebsite.factory.Factory;
import com.zzj.portalwebsite.utlis.CommonResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Date;

@WebServlet("/feedback/save")
public class FeedBackController extends HttpServlet{

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        try {
            //获取反馈人信息
            String name = request.getParameter("name");
            String email = request.getParameter("email");
            String phone = request.getParameter("phone");
            String message = request.getParameter("message");
            String backimg = request.getParameter("backimg");

            FeedBack feedback = new FeedBack(null, name, email, phone, message,null, backimg);

            boolean b = Factory.getFeedBackServiceInstance().subInfo(feedback);
            if (b){
                response.getWriter().write(JSON.toJSONString(CommonResult.success(feedback)));
            }else {
                response.getWriter().write(JSON.toJSONString(CommonResult.failed("反馈失败")));
            }


        }catch (Exception e){
            e.printStackTrace();
            response.getWriter().write(JSON.toJSONString(CommonResult.failed("反馈失败")));

        }


    }
}
